$(function () {
    $("#jqGrid").Grid({
        url: '../toolsstorepos/list',
        loadError: function (jqXHR, textStatus, errorThrown) {
            // 目前只处理查询过多的条件
            iview.Message.error("匹配当前查询条件的记录数过多，请进一步细化查询条件！");
            return;
        },
        rownumWidth: 50,
        colModel: [
            {label: '工装名称', name: 'toolsName', index: 'toolsName', width: 80},
            {label: '型号规格', name: 'spec', index: 'spec', width: 80},
            {label: '工装编码', name: 'toolsCode', index: 'TOOLS_CODE', width: 80,frozen: true},
            {label: '图号', name: 'mapNo', index: 'MAP_NO', width: 120,frozen: true},
            {label: '工装类别', name: 'typeName', index: 'TOOLS_TYPE', width: 80},
            {label: '仓库名称', name: 'storeName', width: 120},
            {label: '库位', name: 'postion', index: 'POSTION', width: 60},
            {label: '库存数', name: 'storeNum', index: 'STORE_NUM', width: 40},
            {label: 'id', name: 'id', index: 'ID', key: true, hidden: true},
            {name: 'storeId', hidden: true},
            {name: 'locNum', hidden: true},

        ]
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        title: null,
        toolsStock: {
            updateTime: '',
            updateUser: '',
            createUser: '',
            createTime: '',
            delFlag: '',
            remark: '',
            approvalTime: '',
            approvalUser: '',
            stockNum: '',
            safeStock: '',
            inTime: '',
            belongTools: '',
            useWorkProcedure: '',
            useUnit: '',
            factory: '',
            inNum: '',
            price: '',
            unit: '',
            specs: '',
            name: '',
            erpCode: '',
            inNo: '',
            resources: 0,
            cargoLocation: '',
            workshop: '',
            workshopName: '',
            id: '',
            approvalStstus: '',
        },

        q: {
            name: ''
        },
        resourcesList:enumsToList('RESOURCES_TYPE')
    },

    methods: {
        query: function () {
            vm.reload();
        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: vm.q,
                page: page
            }).trigger("reloadGrid");
            vm.handleReset('formValidate');
        },
        reloadSearch: function () {
            vm.q = {
                name: ''
            };
            vm.reload();
        },
        handleSubmit: function (name) {
            handleSubmitValidate(this, name, function () {
                vm.saveOrUpdate()
            });
        },
        handleReset: function (name) {
            handleResetForm(this, name);
        },

    }
});

var getToolsStroe = function () {
    let result = getSelectedRowData("#jqGrid");
    var id = result.id;
    if (id == null) {
        return false;
    } else {
        return result;
    }
}